package org.hades.corelib.base.data

import org.hades.corelib.base.exception.ApiException
import org.hades.corelib.base.exception.EmptyException

open class NetResult<T> constructor(
    var code: Int = -1,
    var message:String = "未配置",
    var data:T? = null
): INetResult<T> {
   final val SUCCESS :Int = 1000


    override fun checkCode() {
        when (code) {
            5000 -> {
                throw ApiException(code, message)
            }
        }

    }

    override fun checkData() {
        if (null == this.data) throw EmptyException()
        if (this.data is Collection<*> && (this.data as Collection<*>).isEmpty()){
            throw EmptyException()
        }
    }

    override fun data(): T? {
       return data
    }
}